package com.hfjava.practice03;

import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: com.hfjava.practice03
 * @ClassName: Goods
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/21 8:59
 * @Copyright 大牛版板所有
 */
public class Goods {
    public static void main(String[] args) {
        String[] goodsName = {"电风扇","洗衣机","电视机","冰箱","空调机"};
        double[] goodsPrice = {124.23, 4500.0, 8800.9, 5000.88, 4456.0};

        // 显示商品信息

        System.out.println("===========欢迎进入商品批发商城============");
        System.out.println("\t\t编号\t商品\t价格");
        for (int i = 0; i < goodsPrice.length; i++) {
            StringBuffer price = new StringBuffer(Double.toString(goodsPrice[i]));
            for (int j = price.indexOf(".")-3; j >0 ; j=j-3) {
                price.insert(j,",");
            }
            System.out.println("\t\t"+(i+1)+"\t\t"+goodsName[i]+"\t"+price);
        }
        System.out.println("==========================================");

        // 用户输入选择
        Scanner input = new Scanner(System.in);
        System.out.print("请输入你批发商品的编号：");
        int number = input.nextInt();
        System.out.print("请输入批发数量：");
        int num = input.nextInt();
        double totalPri = num*goodsPrice[number-1];
        String t = Double.toString(totalPri);
        StringBuffer total = new StringBuffer(t);
        for (int i = total.indexOf(".")-3;i>0; i=i-3) {
            total.insert(i,",");
        }
        System.out.println("你需要付款："+total);

    }
}
